﻿Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Data
Imports System.Drawing.Printing
Imports System.Collections.Generic
Partial Class Seuss_PeaD_frmPEaDReport
    Inherits System.Web.UI.Page
    Dim Report As New ReportDocument
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            LoaderData()
        Catch ex As Exception
            lblError.Text = ex.Message '& "---" & ex.InnerException.Message
        End Try
    End Sub
    Sub LoaderData(Optional ByVal Print As Integer = 0)
        Dim nRepTipo As Integer = Request.QueryString("nRepTipo")
        Dim cReportRuta As String = String.Empty
        Dim nPrdCodigo As String = Request.QueryString("nPrdCodigo")
        Dim nUniOrgCodigo As Long = Request.QueryString("nUniOrgCodigo")
        Dim cRepTitle As String = Request.QueryString("cRepTitle")
        Dim cRepComments As String = Request.QueryString("cRepComments")
        Dim cPerCodigo As String = Request.QueryString("cPerCodigo")
        Dim cPerJurCodigo As String = Request.QueryString("cPerJuridica")
        Dim OtherType As Long = Request.QueryString("OtherType")
        Dim cPrdDescripcion As String = Request.QueryString("cPrdDescripcion")
        Dim cFecIni As String = Request.QueryString("cFecIni")
        Dim cFecFin As String = Request.QueryString("cFecFin")
        Dim nPerRemFiltro As Integer = Request.QueryString("nPerRemFiltro")
        Dim nPerRecFiltro As Integer = Request.QueryString("nPerRecFiltro")

        Dim Comando As New DataTable


        'Dim Impresora As New PrinterSettings
        Dim MiConexion As String = TramiteDocumentario.ModTraDoc.MiConexion
        Using Cn As New SqlConnection(MiConexion)
            Cn.Open()
            Dim MyTrans As SqlTransaction = Cn.BeginTransaction

            Try
                Dim clsTraDoc As New TramiteDocumentario.clsTraDoc

                Select Case nRepTipo
                    Case 1
                        cReportRuta = Server.MapPath("~/Report/rptTDAcuerdos.rpt")
                        Comando.Load(clsTraDoc.Get_Acuerdos_By_Persona_OR_Fecha(cPerCodigo, cFecIni, cFecFin, MyTrans, Cn))

                    Case 2                      
                        cReportRuta = Server.MapPath("~/Report/rptTDDocBusca.rpt")
                        Comando.Load(clsTraDoc.Get_Busca_Doc_Whit_Filtro(cPerCodigo, nPerRemFiltro, nPerRecFiltro, 0, 0, "", 0, "", nPrdCodigo, 0, 0, MyTrans, Cn))
                End Select

                Report.Load(cReportRuta)
                Report.SummaryInfo.ReportAuthor = "Impreso por :" & Session("cPerCodigo")
                Report.SummaryInfo.ReportTitle = cRepTitle
                Report.SummaryInfo.ReportComments = cRepComments
                Report.SetDataSource(Comando)

                Me.crptPEaDReport.ReportSource = Report

                MyTrans.Commit()
                Cn.Close()

            Catch ex As Exception
                Throw
            End Try
        End Using
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        'LoaderData(1)
    End Sub

    Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
        If Not Report Is DBNull.Value And Report.IsLoaded Then
            Report.Close()
        End If
    End Sub
End Class
